from fastapi import APIRouter, Depends, status
from pydantic import BaseModel

from conf import variable
from conf.mysql_cnx import MysqlCnxPool
from dependencies import get_current_user
from service import user_report
from service.user_report import User

router = APIRouter(prefix=variable.CONTEXT_PATH + '/admin',
                   tags=['admin'],
                   dependencies=[Depends(get_current_user)])


class AssignReportsToUserItem(BaseModel):
    username: str
    quantity: int


@router.post('/assign_reports_to_user')
async def assign_reports_to_user(item: AssignReportsToUserItem):
    user_report.assign_reports_to_user(item.username, item.quantity)
    return {'code': status.HTTP_200_OK, 'message': '', 'payload': {}}


@router.post('/assign_reports_to_all_user')
async def assign_reports_to_all_user():
    session = MysqlCnxPool().get_session()
    users = session.query(User).all()
    for user in users:
        user_report.assign_reports_to_user(user.id, 50)
    return {'code': status.HTTP_200_OK, 'message': '', 'payload': {}}
